import { createRouter, createWebHistory } from 'vue-router'
import { setupRouterGuard } from './permission'

const routes = [
  { path: '/login', component: () => import('@/views/login/index.vue') },
  {
    path: '',
    name: 'layout',
    component: () => import('@/layouts/DefaultLayout.vue'),
    redirect: '/index',
    children: [
      // { path: '', name: 'default', redirect: '/index' },
      // {
      //   path: 'index',
      //   name: 'index',
      //   component: () => import('@/views/dashboard/index.vue'),
      // },
      // {
      //   path: 'system/user',
      //   name: 'system-user',
      //   component: () => import('@/views/system/user.vue'),
      // },
      // {
      //   path: 'system/role',
      //   name: 'system-role',
      //   component: () => import('@/views/system/role.vue'),
      // },
      // {
      //   path: 'system/permission',
      //   name: 'system-permission',
      //   component: () => import('@/views/system/permission.vue'),
      // },
      // {
      //   path: 'system/menu',
      //   name: 'system-menu',
      //   component: () => import('@/views/system/menu.vue'),
      // },
      // { path: 'system/config', name: 'system-config', component: () => import('@/views/config/ConfigManagement.vue') },
      // {
      //   path: 'system/dept',
      //   name: 'system-dept',
      //   component: () => import('@/views/system/dept.vue'),
      // },
      // { path: 'meta/model', name: 'meta-model', component: () => import('@/views/meta/model.vue') },
      // { path: 'meta/field', name: 'meta-field', component: () => import('@/views/meta/field.vue') },
      // {
      //   path: 'lowcode/form-designer',
      //   name: 'lowcode-form-designer',
      //   component: () => import('@/views/lowcode/form-designer.vue'),
      // },
      // {
      //   path: 'lowcode/forms',
      //   name: 'lowcode-forms',
      //   component: () => import('@/views/lowcode/forms.vue'),
      // },
      // {
      //   path: 'lowcode/form-data',
      //   name: 'lowcode-form-data',
      //   component: () => import('@/views/lowcode/form-data.vue'),
      // },
      // {
      //   path: 'plugin/market',
      //   name: 'plugin-market',
      //   component: () => import('@/views/plugin/market.vue'),
      // },
      // {
      //   path: 'plugin/installed',
      //   name: 'plugin-installed',
      //   component: () => import('@/views/plugin/installed.vue'),
      // },
      // { path: 'plugin/detail/:id', component: () => import('@/views/plugin/detail.vue') },
      // {
      //   path: 'profile/info',
      //   name: 'profile-info',
      //   component: () => import('@/views/profile/info.vue'),
      // },
      // {
      //   path: 'profile/password',
      //   name: 'profile-password',
      //   component: () => import('@/views/profile/password.vue'),
      // },
    ],
  },
  { path: '/:pathMatch(.*)*', component: () => import('@/views/error/404.vue') },
]

const router = createRouter({
  history: createWebHistory(),
  routes,
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      return { top: 0 }
    }
  },
})

// 设置路由守卫
setupRouterGuard(router)

export default router
